package cn.tedu.tmall.admin.mall.dao.repository.impl;

import cn.tedu.tmall.admin.mall.dao.repository.IMallCategoryCacheRepository;
import cn.tedu.tmall.common.pojo.po.MallCacheCategoryPO;
import cn.tedu.tmall.common.pojo.vo.MallCategoryTreeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
//@SuppressWarnings("unchecked")
public class MallCategoryCacheRepository implements IMallCategoryCacheRepository {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void saveCategoryTree(List<MallCategoryTreeVO> mallCategoryTreeVOS) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("ALL", mallCategoryTreeVOS);
    }

    @Override
    public void saveCategoryByParentId(Long parentId, MallCacheCategoryPO mallCacheCategoryPO) {
        ListOperations listOperations = redisTemplate.opsForList();
        String key = "MALL_CATEGORY_BY_PARENT_ID_" + parentId;
        listOperations.rightPush(key, mallCacheCategoryPO);
    }

}
